package com.ruoyi.system.controller;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.lang3.ThreadUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ItEvaluate;
import com.ruoyi.system.service.IItEvaluateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评论评价Controller
 * 
 * @author ruoyi
 * @date 2022-01-26
 */
@RestController
@RequestMapping("/mini/evaluate")
public class ItEvaluateController extends BaseController
{
    @Autowired
    private IItEvaluateService itEvaluateService;

    /**
     * 查询评论评价列表
     */
//    @PreAuthorize("@ss.hasPermi('system:evaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItEvaluate itEvaluate)
    {
        startPage();
        List<ItEvaluate> list = itEvaluateService.selectItEvaluateList(itEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出评论评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:export')")
    @Log(title = "评论评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItEvaluate itEvaluate)
    {
        List<ItEvaluate> list = itEvaluateService.selectItEvaluateList(itEvaluate);
        ExcelUtil<ItEvaluate> util = new ExcelUtil<ItEvaluate>(ItEvaluate.class);
        util.exportExcel(response, list, "评论评价数据");
    }

    /**
     * 获取评论评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(itEvaluateService.selectItEvaluateById(id));
    }

    /**
     * 新增评论评价
     */
//    @PreAuthorize("@ss.hasPermi('system:evaluate:add')")
    @Log(title = "评论评价", businessType = BusinessType.INSERT)
    @PostMapping("/adds")
    public AjaxResult adds(@RequestBody ItEvaluate itEvaluate)
    {
        itEvaluate.setId(UUID.randomUUID().toString().replaceAll("-",""));
        if(StringUtils.isEmpty(itEvaluate.getRepliedBy())){
            itEvaluate.setRepliedBy(itEvaluate.getCompanyId());
        }
        return toAjax(itEvaluateService.insertItEvaluate(itEvaluate));
    }

    /**
     * 修改评论评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:edit')")
    @Log(title = "评论评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItEvaluate itEvaluate)
    {
        return toAjax(itEvaluateService.updateItEvaluate(itEvaluate));
    }

    /**
     * 删除评论评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:remove')")
    @Log(title = "评论评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(itEvaluateService.deleteItEvaluateByIds(ids));
    }
}
